/*     */ package com.zimbra.qa.unittest.prov.soap;
/*     */ 
/*     */ import com.google.common.collect.Lists;
/*     */ import com.google.common.collect.Maps;
/*     */ import com.zimbra.common.account.ZAttrProvisioning.DistributionListSubscriptionPolicy;
/*     */ import com.zimbra.common.mailbox.ContactConstants;
/*     */ import com.zimbra.common.soap.SoapTransport;
/*     */ import com.zimbra.cs.account.Account;
/*     */ import com.zimbra.cs.account.Domain;
/*     */ import com.zimbra.cs.account.Group;
/*     */ import com.zimbra.cs.account.Group.GroupOwner;
/*     */ import com.zimbra.cs.account.Provisioning;
/*     */ import com.zimbra.cs.account.accesscontrol.GranteeType;
/*     */ import com.zimbra.cs.account.accesscontrol.Right;
/*     */ import com.zimbra.cs.account.accesscontrol.TargetType;
/*     */ import com.zimbra.qa.unittest.prov.ProvTest.SkipTestReason;
/*     */ import com.zimbra.qa.unittest.prov.Verify;
/*     */ import com.zimbra.soap.account.message.SearchGalRequest;
/*     */ import com.zimbra.soap.account.message.SearchGalResponse;
/*     */ import com.zimbra.soap.account.type.ContactInfo;
/*     */ import com.zimbra.soap.account.type.MemberOfSelector;
/*     */ import com.zimbra.soap.admin.type.GranteeSelector.GranteeBy;
/*     */ import com.zimbra.soap.type.ContactAttr;
/*     */ import com.zimbra.soap.type.TargetBy;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ import org.junit.AfterClass;
/*     */ import org.junit.BeforeClass;
/*     */ import org.junit.Test;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class TestSearchGalGroups
/*     */   extends SoapTest
/*     */ {
/*     */   private static SoapProvTestUtil provUtil;
/*     */   private static Provisioning prov;
/*     */   private static Domain domain;
/*     */   
/*     */   @BeforeClass
/*     */   public static void init()
/*     */     throws Exception
/*     */   {
/*  53 */     provUtil = new SoapProvTestUtil();
/*  54 */     prov = provUtil.getProv();
/*  55 */     domain = provUtil.createDomain(baseDomainName());
/*     */   }
/*     */   
/*     */   @AfterClass
/*     */   public static void cleanup() throws Exception {
/*  60 */     Cleanup.deleteAll(new String[] { baseDomainName() });
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */   private void testSearchGroup(Account acct, Group group, Boolean needIsOwner, MemberOfSelector needIsMember, boolean actualIsOwner, boolean actualIsMember)
/*     */     throws Exception
/*     */   {
/*  69 */     SoapTransport transport = authUser(acct.getName());
/*     */     
/*  71 */     SearchGalRequest req = new SearchGalRequest();
/*  72 */     req.setName(group.getName());
/*  73 */     req.setNeedIsOwner(needIsOwner);
/*  74 */     req.setNeedIsMember(needIsMember);
/*     */     
/*  76 */     SearchGalResponse resp = (SearchGalResponse)invokeJaxb(transport, req);
/*     */     
/*  78 */     List<String> result = Lists.newArrayList();
/*  79 */     List<String> expected = Lists.newArrayList(new String[] { Verify.makeResultStr(new Object[] { group.getName(), "group", needIsOwner == null ? null : Boolean.valueOf(actualIsOwner), needIsMember == null ? null : Boolean.valueOf(actualIsMember), ZAttrProvisioning.DistributionListSubscriptionPolicy.ACCEPT.name() }) });
/*     */     
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*  87 */     List<ContactInfo> entries = resp.getContacts();
/*  88 */     for (ContactInfo entry : entries) {
/*  89 */       List<ContactAttr> attrs = entry.getAttrs();
/*     */       
/*  91 */       String email = null;
/*  92 */       String type = null;
/*  93 */       String subsPolicy = null;
/*     */       
/*  95 */       for (ContactAttr attr : attrs) {
/*  96 */         String key = attr.getKey();
/*  97 */         if (ContactConstants.A_email.equals(key)) {
/*  98 */           email = attr.getValue();
/*  99 */         } else if (ContactConstants.A_type.equals(key)) {
/* 100 */           type = attr.getValue();
/* 101 */         } else if ("zimbraDistributionListSubscriptionPolicy".equals(key)) {
/* 102 */           subsPolicy = attr.getValue();
/*     */         }
/*     */       }
/*     */       
/* 106 */       Boolean isOwner = entry.isOwner();
/* 107 */       Boolean isMember = entry.isMember();
/*     */       
/* 109 */       result.add(Verify.makeResultStr(new Object[] { email, type, isOwner, isMember, subsPolicy }));
/*     */     }
/* 111 */     Verify.verifyEquals(expected, result);
/*     */   }
/*     */   
/*     */   @Test
/*     */   public void searchGroup() throws Exception {
/* 116 */     SKIP_FOR_INMEM_LDAP_SERVER(ProvTest.SkipTestReason.DN_SUBTREE_MATCH_FILTER);
/*     */     
/* 118 */     Map<String, Object> attrs = Maps.newHashMap();
/* 119 */     attrs.put("zimbraDistributionListSubscriptionPolicy", ZAttrProvisioning.DistributionListSubscriptionPolicy.ACCEPT.name());
/*     */     
/* 121 */     Group group = provUtil.createGroup(genGroupNameLocalPart(), domain, attrs, false);
/* 122 */     Account acct = provUtil.createAccount(genAcctNameLocalPart(), domain);
/*     */     
/*     */ 
/* 125 */     String right = Group.GroupOwner.GROUP_OWNER_RIGHT.getName();
/* 126 */     prov.grantRight(TargetType.dl.getCode(), TargetBy.name, group.getName(), GranteeType.GT_USER.getCode(), GranteeSelector.GranteeBy.name, acct.getName(), null, right, null);
/*     */     
/*     */ 
/*     */ 
/*     */ 
/* 131 */     prov.addGroupMembers(group, new String[] { acct.getName() });
/*     */     
/*     */ 
/* 134 */     GalTestUtil.enableGalSyncAccount(prov, domain.getName());
/* 135 */     testSearchGroup(acct, group, Boolean.TRUE, MemberOfSelector.all, true, true);
/* 136 */     testSearchGroup(acct, group, Boolean.TRUE, null, true, true);
/* 137 */     testSearchGroup(acct, group, null, MemberOfSelector.all, true, true);
/* 138 */     testSearchGroup(acct, group, null, null, true, true);
/*     */     
/*     */ 
/* 141 */     GalTestUtil.disableGalSyncAccount(prov, domain.getName());
/* 142 */     testSearchGroup(acct, group, Boolean.TRUE, MemberOfSelector.all, true, true);
/* 143 */     testSearchGroup(acct, group, Boolean.TRUE, null, true, true);
/* 144 */     testSearchGroup(acct, group, null, MemberOfSelector.all, true, true);
/* 145 */     testSearchGroup(acct, group, null, null, true, true);
/*     */     
/* 147 */     provUtil.deleteGroup(group);
/* 148 */     provUtil.deleteAccount(acct);
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/qa/unittest/prov/soap/TestSearchGalGroups.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */